Repository navigation
Conversation
increase() and rate() count the change between samples, never a series' first sample. The handler exposed a new counter at its first value and expired idle series after MetricTimeout, so a counter first scraped at 3 lost those 3, and a series expired and re-created at 1 read as no change. Busy series lose this once per process. Sparse, high-cardinality series, such as a counter labelled by a per-customer ID that sees a few requests and goes idle, lose it every time they come back, and read several percent low against the same counter sent to a statsd backend. New and re-created counter and histogram series are now published as 0 for Handler.ZeroPeriod before their real value. The period is measured on the wall clock, not per scrape, so every scraper sees the zero. It defaults to 2 minutes, twice the common 60s scrape interval, so a late scrape or a target moving between collectors still lands in it. A series is not expired during its zero period, and its value is published for a full MetricTimeout afterwards, so counts are delayed rather than lost. Gauges are unchanged; a negative ZeroPeriod turns this off. Tests that read values right after the first update now set ZeroPeriod: -1. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
increase()andrate()count the change between scraped samples, never a series' first sample. The Prometheus handler exposed a new counter at its first value and expired idle series afterMetricTimeout. So a counter first scraped at 3 lost those 3, and a series expired and re-created at 1 read as no change at all.New and re-created counter and histogram series are now published as 0 for the new
Handler.ZeroPeriodbefore their real value:curl /metrics.MetricTimeoutafterwards.ZeroPeriodturns it off.Why
Busy series hit this once per process. Sparse, high-cardinality series hit it every time they come back. A good example is a response counter labelled by a per-customer ID, where each series sees a few requests, goes idle, expires and returns. Such a counter can read several percent low against the same counter sent to a statsd backend, while a request counter on the same process, labelled only by endpoint, matches. Raising
MetricTimeoutreduces how often series come back, but every new series still loses its first value.Tests
prometheus/zero_test.go:TestZeroPeriodCountsEveryIncrementsimulates 30 minutes of traffic scraped every 15s: one busy series, plus three per-customer series that are expired between bursts. It sumsincrease()per series the way Prometheus does. With the zero period off, it counts 1907 of 1914 increments. With the default, it counts all 1914.TestZeroPeriodIsTimeBased: repeated scrapes inside the window all see 0 for the counter, buckets,_sumand_count, and the gauge is unaffected. The real values appear once the window ends.TestZeroPeriodOutlivesExpiry: a series is kept through its zero period and for a fullMetricTimeoutafter it.The handler's wall clock now goes through a package-level
nowso these tests can step time.Ten existing tests read values right after the first update, to check names and buckets. They now set
ZeroPeriod: -1.go test ./...,go test -race ./prometheus/,go vetandgofmtpass.golangci-lintwas not run locally.HISTORY.md has a v5.12.0 entry, and README.md documents
ZeroPeriod.🤖 Generated with Claude Code